package com.lengchangjing.BehavioralPatterns.InterpreterPattern.example;

public class Client {
    public static void main(String[] args) {
        // 初始化上下文
        Context ctx = new Context();
        // 设置变量、常量
        Variable a = new Variable();
        Variable b = new Variable();
        Constant c = new Constant(2);
        // 为变量赋值
        ctx.assign(a,6);
        ctx.assign(b,3);
        // 运算，(6 ÷ 3) + 2
        Expression expression = new Add(new Division(a,b),c);
        System.out.println("(6 ÷ 3) + 2 = " + expression.interpret(ctx));
    }
}
